import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

class MyToolBox extends JToolBar 
{      	  	
    public static final byte BUTTON = 1;
    public static final byte CHECKBOX = 2;    
    public static final byte COMBOBOX = 3;
    public static final byte LABEL = 4;
    public static final byte LIST = 5;
    public static final byte PICTURE = 6;
    public static final byte RADIOBUTTON = 7;
    public static final byte TEXTFIELD = 8;
    public static final byte TOGGLEBUTTON= 9;
    public static final byte LINE = 10;
    public static final byte RECTANGLE = 11;
    public static final byte CIRCLE = 12;
    public static final byte CURSOR = 13;
    
    private byte selected;
    private boolean pressed;    
    
    private ImageIcon toolButtonIcon = new ImageIcon(getClass().getResource("Images/ToolButton.png"));	
    private ImageIcon toolImageButtonIcon = new ImageIcon(getClass().getResource("Images/ToolImage.png"));        
    private ImageIcon toolComboBoxIcon = new ImageIcon(getClass().getResource("Images/ToolComboBox.png"));	
    private ImageIcon toolCheckBoxIcon = new ImageIcon(getClass().getResource("Images/ToolCheckBox.png"));	
    private ImageIcon toolListBoxIcon = new ImageIcon(getClass().getResource("Images/ToolListBox.png"));	
    private ImageIcon toolTextboxIcon = new ImageIcon(getClass().getResource("Images/TextBox.png")); 	
    private ImageIcon toolLabelIcon = new ImageIcon(getClass().getResource("Images/Label.png"));         
    private ImageIcon toolOptionIcon = new ImageIcon(getClass().getResource("Images/OptionButton.png")); 	
    private ImageIcon toolCursorIcon = new ImageIcon(getClass().getResource("Images/Cursor.png")); 	
    private ImageIcon toolToggleIcon = new ImageIcon(getClass().getResource("Images/ToggleButton.png"));	
    private ImageIcon toolLineIcon = new ImageIcon(getClass().getResource("Images/Line.png"));	
    private ImageIcon toolRectangleIcon = new ImageIcon(getClass().getResource("Images/Rectangle.png")); 	
    private ImageIcon toolCircleIcon =  new ImageIcon(getClass().getResource("Images/Circle.png"));

    private JButton toolButton = new JButton (toolButtonIcon);
    private JButton toolImage = new JButton (toolImageButtonIcon);
    private JButton toolComboBox = new JButton (toolComboBoxIcon);
    private JButton toolListBox = new JButton (toolListBoxIcon);
    private JButton toolCheckBox = new JButton (toolCheckBoxIcon);
    private JButton toolTextbox= new JButton (toolTextboxIcon);
    private JButton toolLabel= new JButton (toolLabelIcon);
    private JButton toolOption= new JButton (toolOptionIcon);
    private JButton toolCursor= new JButton (toolCursorIcon);
    private JButton toolToggle= new JButton (toolToggleIcon);
    private JButton toolLine= new JButton (toolLineIcon);
    private JButton toolRectangle= new JButton (toolRectangleIcon);
    private JButton toolCircle= new JButton (toolCircleIcon);
    protected MyFrame.DesignPanel panel;

    public byte getSelected(){ return selected; }
    public boolean isPressed() { return pressed;}
    public void setPressed(boolean b){ pressed = b;}
    public void setSelected(byte selection){selected=selection;}
    
    MyToolBox(MyFrame.DesignPanel designpanel)
      {
        super("Tool Box",JToolBar.VERTICAL);
        panel=designpanel;
        toolButton.setToolTipText("Button");
        toolImage.setToolTipText("Image");
        toolComboBox.setToolTipText("Combo Box");
        toolListBox.setToolTipText("List Box");
        toolCheckBox.setToolTipText("Check Box");        
        toolTextbox.setToolTipText("TextBox");
        toolLabel.setToolTipText("Label");
        toolToggle.setToolTipText("Toggle Button");
        toolOption.setToolTipText("Option");
        toolCursor.setToolTipText("Cursor");
        toolLine.setToolTipText("Line");
        toolRectangle.setToolTipText("Rectangle");
        toolCircle.setToolTipText("Circle");

        setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
        //setFloatable(false);
        //setLocation(50,50);
        //setSize(50,520);
        add(toolCursor);
        addSeparator();
        add(toolLabel);
        add(toolTextbox);
        add(toolButton);
        add(toolComboBox);
        add(toolImage);
        add(toolCheckBox);
        add(toolListBox);
        add(toolToggle);
        add(toolOption);
        add(toolLine);
        add(toolRectangle);
        add(toolCircle);
        setOpaque(true);
        
        //**********Add Events************************/////////////
         toolToggle.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            { 
                selected=TOGGLEBUTTON;                
                pressed = true;
                panel.requestFocusInWindow();
            }
          });
          
        toolButton.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            { 
                selected=BUTTON;
                pressed = true;
                panel.requestFocusInWindow();
            }
          });

        toolImage.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=PICTURE;                    
                pressed = true;
                panel.requestFocusInWindow();
            }
          });

        toolComboBox.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=COMBOBOX;                    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });

         toolCheckBox.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=CHECKBOX;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });

         toolListBox.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=LIST;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });

         toolTextbox.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=TEXTFIELD;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });

         toolLabel.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=LABEL;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });

         toolOption.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=RADIOBUTTON;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });
          
         toolCursor.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=CURSOR;    
                pressed = false;
                panel.requestFocusInWindow();
            }
         });
        
         toolLine.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=LINE;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });
         
         toolRectangle.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=RECTANGLE;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });
         
         toolCircle.addMouseListener(new MouseAdapter()
         {
            public void mouseClicked(MouseEvent e)
            {
                selected=CIRCLE;    
                pressed = true;
                panel.requestFocusInWindow();
            }
         });         
    }	  	  	
  }